package com.xgry.bpm.api.base.role.service.impl;

import com.xgry.bpm.api.base.role.entity.Role;
import com.xgry.bpm.api.base.role.mapper.RoleMapper;
import com.xgry.bpm.api.base.role.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * Role服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-09
*/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>implements RoleService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public Role selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        Role data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<Role>selectAll(Role record){
        QueryWrapper<Role>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<Role>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<Role>selectPage(IPage<Role> page , Role record){
        // 查询条件
        QueryWrapper<Role>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<Role>getPage(IPage<Role>page,QueryWrapper<Role>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }
}